home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1097 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news1.cle.ab.com!usenet
  2. From: don.phillips@ab.com (Donald-Anthony C. Phillips)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How do you pass along a variable argument list?
  5. Date: Thu, 11 Jan 1996 16:10:50 GMT
  6. Organization: The Allen-Bradley Co., Inc
  7. Distribution: inet
  8. Message-ID: <4d328r$vs@news1.cle.ab.com>
  9. References: <4d1i8v$k8h@news.mcl.bdm.com>
  10. NNTP-Posting-Host: abpc386.cle.ab.com
  11. X-Newsreader: Forte Free Agent 1.0.82
  12.  
  13. The method is as follows:
  14.  
  15.     int myfunc(char *myarg, ...)
  16.  
  17. Yes! It's as simple as adding elipses to the end of the argument list.
  18.  
  19.  
  20. You can then step through the argument list using the <stdarg.h>
  21. header file which contains macros for stepping.  
  22.  
  23. The type 'va_list' is used to declare a varible for pointing to each
  24. unnamed argument.  There's a macro ' va_start'  which initializes your
  25. variable of type 'va_list'  to point to the first unnamed argument.
  26.  
  27. Macro 'va_arg' actually returns the next argument and steps for you
  28. and lastly 'va_end' does some cleanup work when your done.
  29.  
  30. The 'C Programmng Language' by K&R has a complete explanation of
  31. variable length arguments in chapter 7.
  32.  
  33.  
  34. Donald-Anthony C. Phillips
  35. Programmer/Analyst
  36.  Rockwell  Automation
  37.        ---------------------------------------
  38.         Allen-Bradley
  39. don.phillips@ab.com
  40.  
  41.